<?php
/*
+-----------------------------------------------------------------------------+
| $Id: index.php 2010-05-24 12:37:44Z Bleakwind $
| System admin index
| Copyright (c) 2003-2010 Bleakwind (www.weaverdream.com)
| http://www.weaverdream.com/
| Release under the GNU Lesser General Public License Version 3 (LGPLv3):
|   http://www.gnu.org/licenses/lgpl.html
+-----------------------------------------------------------------------------+
*/

if (!defined( 'ENTRY_INDEX')){
    echo "<h1>Forbidden</h1><p>You don't have permission to access on this server.</p>";
    exit;
}

if ($sys->get['act'] == "prompt_forbid") {
    if ($MEMBER['mg_privilege']['if_forbidvisit'] != "1" ) {
        $sys->prompt("jump", $CONFIGURE['common']['control_admin']."?act=index.php");
    } 
} else {
    // article_list
    $where          = "";
    $where_total    = "";

    $where          .= " AND ((article.if_enable=1) || (article.if_enable=3 AND article.if_enable_begin<".$sys->nowtime." AND article.if_enable_end>".$sys->nowtime."))";
    $where_total    .= " AND ((if_enable=1) || (if_enable=3 AND if_enable_begin<".$sys->nowtime." AND if_enable_end>".$sys->nowtime."))";

    $where       = substr(trim($where), 0, 3) == "AND" ? substr(trim($where), 3) : trim($where);
    $where_total = substr(trim($where_total), 0, 3) == "AND" ? substr(trim($where_total), 3) : trim($where_total);
    $where       = $where != "" ? "WHERE ".$where : "";
    $where_total = $where_total != "" ? "WHERE ".$where_total : "";

    $sql = "SELECT article.*,
                cover.id as cover_id, cover.dir as cover_dir, cover.filename as cover_filename
            FROM ".DB_TABLE_ARTICLE." article
                LEFT JOIN ".DB_TABLE_ARTICLE_COVER." cover ON cover.article_id=article.id
            ".$where."
            ORDER BY article.if_top, article.post_time DESC, article.id DESC
            LIMIT 0,5";
    $result = &$db->Execute($sql);
    if (!$result) {
        echo $db->ErrorMsg();
    } else {
        while (!$result->EOF) {
            $article_list[] = array(
                'id'                    => $result->fields['id'],
                'phrase'                => $result->fields['phrase'],
                'phrase_len'            => mb_strwidth($result->fields['phrase'],"UTF-8"),
                'subject'               => $result->fields['subject'],
                'subject_len'           => mb_strwidth($result->fields['subject'],"UTF-8"),
                'prefix'                => $result->fields['prefix'],
                'color'                 => $result->fields['color'],
                'fontstyle'             => $result->fields['fontstyle'],
                'decoration'            => $result->fields['decoration'],
                'keyword'               => $result->fields['keyword'],
                'brief'                 => $result->fields['brief'],
                'post_id'               => $result->fields['post_id'],
                'post_username'         => $result->fields['post_username'],
                'post_ip'               => $result->fields['post_ip'],
                'post_time'             => $result->fields['post_time'],
                'amend_id'              => $result->fields['amend_id'],
                'amend_username'        => $result->fields['amend_username'],
                'amend_ip'              => $result->fields['amend_ip'],
                'amend_time'            => $result->fields['amend_time'],
                'click'                 => $result->fields['click'],
                'if_enable'             => $result->fields['if_enable'],
                'if_enable_begin'       => $result->fields['if_enable_begin'],
                'if_enable_end'         => $result->fields['if_enable_end'],
                'if_top'                => $result->fields['if_top'],
                'if_top_begin'          => $result->fields['if_top_begin'],
                'if_top_end'            => $result->fields['if_top_end'],
                'if_turn'               => $result->fields['if_turn'],
                'if_turn_url'           => $result->fields['if_turn_url'],

                'cover_id'              => $result->fields['cover_id'],
                'cover_dir'             => $result->fields['cover_dir'],
                'cover_filename'        => $result->fields['cover_filename'],
            );
            $result->MoveNext();
        }
    }
    $t->assign(array(
        "article_list"  => $article_list,
    ));
}
?>
